package com.qs.eggs.integral.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import com.facebook.drawee.view.SimpleDraweeView;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.qs.eggs.Constants;
import com.qs.eggs.R;
import com.qs.eggs.adapter.BaseViewHolder;
import com.qs.eggs.adapter.SimpleAdapter;
import com.qs.eggs.integral.IntegralBean;
import com.qs.eggs.integral.DetailList;
import com.qs.eggs.integral.activity.SelectAddressActivity;

import java.lang.reflect.Type;
import java.util.ArrayList;

public class ExchangeOrderAdapter extends SimpleAdapter<IntegralBean> {
    ArrayList<DetailList> resultBean1;
    Type type;
    GsonBuilder gsonBuilder;
    public ExchangeOrderAdapter(Context context, ArrayList<IntegralBean> datas) {
        super(context, R.layout.item_integral_order, datas);
        type = new TypeToken<ArrayList<DetailList>>() {
        }.getType();
        gsonBuilder = new GsonBuilder();

    }

    @Override
    protected void convert(BaseViewHolder viewHoder, final IntegralBean item, int position) {
        resultBean1= gsonBuilder.create().fromJson(item.getDetaillist(), type);
        final DetailList detailList= resultBean1.get(0);

//6274f38df77eb24a17e0c7917c06ded7
        SimpleDraweeView draweeView = (SimpleDraweeView) viewHoder.getView(R.id.propic);
        draweeView.setImageURI(Constants.URL_BASE+"productimages/"+detailList.getAutoname());
        viewHoder.getTextView(R.id.tv_count).setText("X"+detailList.getCount());
        viewHoder.getTextView(R.id.tv_content).setText(detailList.getProname());
        viewHoder.getTextView(R.id.tv_order).setText("订单号："+item.getOrderno());
        viewHoder.getTextView(R.id.tv_createtime).setText(item.getCreatetime());
        viewHoder.getTextView(R.id.tv_total).setText("共"+item.getTotalcount()+"件商品，总积分"+item.getTotalchangezone());
        viewHoder.getTextView(R.id.tv_topay).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context, SelectAddressActivity.class);

                intent.putExtra("orderno",item.getOrderno());
                intent.putExtra("buniessid",item.getBusinessid());
                context.startActivity(intent);

            }
        });
        if (item.getOrderstatus().equals("0")){
            viewHoder.getTextView(R.id.tv_status).setText("未兑换");
            viewHoder.getTextView(R.id.tv_topay).setVisibility(View.VISIBLE);

        }else {
            viewHoder.getTextView(R.id.tv_status).setText("已兑换");
            viewHoder.getTextView(R.id.tv_topay).setVisibility(View.GONE);


        }

    }

   /* @Override
    protected void convert(BaseViewHolder viewHoder, DetailList item,final int posion) {
//6274f38df77eb24a17e0c7917c06ded7
//        ArrayList<DetailList> resultBean = gsonBuilder.create().fromJson(item.getDetaillist(), type);
//        lastList.add(resultBean);
//      //  String proname=lastList.get(posion).get(0).getProname();
//        String price=lastList.get(posion).get(0).getPrice();
//        String count=lastList.get(posion).get(0).getCount();
////        if("null".equals(proname)){
////            proname="";
////        }
//        if("null".equals(price)){
//            price="0";
//        }
//        if("null".equals(count)){
//            count="0";
//        }
       // viewHoder.getTextView(R.id.tv_content).setText(proname);
      //  viewHoder.getTextView(R.id.tv_price).setText(price);
        viewHoder.getTextView(R.id.tv_count).setText(item.getPrice());
//        SimpleDraweeView draweeView = (SimpleDraweeView) viewHoder.getView(R.id.propic);
//        draweeView.setImageURI(Constants.URL_BASE+"productimages/"+item.getAutoname());
//        viewHoder.getTextView(R.id.tv_exchange).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//
//            }
//        });
    }*/
}
